home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 3
/
BBS in a box - Trilogy III.iso
/
Files
/
Prog
/
B-C
/
C++Source Code Fmtr Folder
/
Tests
/
UDialog.cp
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Text File
|
1991-01-10
|
98.2 KB
|
3,741 lines
|
[
TEXT/MPS
]
//$P
//[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]
// UDDialog.inc1.p
/* Copyright © 1988-1990 Apple Computer Inc. All rights reserved. */
#include "MacApp.h"
#include "ToolUtils.h" //GetIndString
#include "Resources.h" //GetResource
#include "Packages.h" //StringToNum
#include "Sane.h" //Decimal
#include "Strings.h" //p2cstr
//RCR UList, UAssociation, Editions, Dialogs, UApplication, UDocument, UWindow, UScroller,
//RCR UFailure, UMacAppUtilities, UErrorMgr, UPatch, UMacAppGlobals, Errors, UPopUp, SysEqu, Traps,
//RCR Devices, ULoMem, UViewCoords, Menus, UMenuMgr, Sane, Script, ToolUtils, Packages, Resources,
//RCR UAdorners();
TAssociation* gParamTxt; // Used for text substitution
TDialogTEView* gFloatingTEView; // The floating TEView used with edit text fields.
//--------------------------------------------------------------------------------------------------
#pragma segment DlgInit
pascal void InitUDialog(void)
{
if (qTemplateViews)
{
// So the linker doesn't dead strip these
DontDeadStrip(TDialogView);
DontDeadStrip(TControl);
DontDeadStrip(TButton);
DontDeadStrip(TCheckBox);
DontDeadStrip(TRadio);
DontDeadStrip(TCluster);
DontDeadStrip(TIcon);
DontDeadStrip(TPicture);
DontDeadStrip(TPopup);
DontDeadStrip(TStaticText);
DontDeadStrip(TEditText);
DontDeadStrip(TNumberText);
DontDeadStrip(TPattern);
RegisterStdType("TDialogView", kStdDialogView);
RegisterStdType("TControl", kStdControl);
RegisterStdType("TButton", kStdButton);
RegisterStdType("TCheckBox", kStdCheckBox);
RegisterStdType("TRadio", kStdRadio);
RegisterStdType("TCluster", kStdCluster);
RegisterStdType("TIcon", kStdIcon);
RegisterStdType("TPicture", kStdPicture);
RegisterStdType("TPopup", kStdPopup);
RegisterStdType("TStaticText", kStdStaticText);
RegisterStdType("TEditText", kStdEditText);
RegisterStdType("TNumberText", kStdNumberText);
RegisterStdType("TPattern", kStdPattern);
}
gFloatingTEManager = new TFloatingTEManager;
gFloatingTEManager->IObject();
/*!!! Create the dictionary for the global text substitution mechanism.
This should move out of UDialog soon */
gParamTxt = new TAssociation;
gParamTxt->IAssociation();
gUDialogInitialized = TRUE;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TDialogTEView* AquireFloatingTEView()
{
if (gFloatingTEManager != NULL)
return (gFloatingTEManager->AquireFloatingTE());
else
return NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
{
if (gFloatingTEManager != NULL)
gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void MAParamText(const Str255& keyStr, const Str255& valueStr)
{
gParamTxt->InsertEntry(keyStr, valueStr);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
//RCR Iteration object
typedef pascal void (*DoToEntryType) (TEntry* anEntry, void* staticLink) ;
typedef pascal void (*DoToObjectType) (TObject* anEntry, void* staticLink) ;
class CReplaceOnce
{
Str255& fTheText;
public:
// Constructor
CReplaceOnce(Str255& theText):fTheText (theText) {};
pascal void ReplaceOnce(TEntry* anEntry);
};
#pragma segment DlgRes
pascal void CReplaceOnce::ReplaceOnce(TEntry* anEntry)
{
/*RCR
do
{
short index;
index = Pos(**(anEntry->fKey), theText);
if (index > 0)
{
Delete(theText, index, Length(**(anEntry->fKey);
if (Length(theText) + Length(**(anEntry->fValue)) < sizeof(Str255))
Insert(**(anEntry->fValue), theText, index);
}
}
while (index != 0);
*/
}
#pragma segment DlgRes
pascal void MAReplaceText(Str255& theText)
{
CReplaceOnce aCReplaceOnce(theText);
gParamTxt->fEntries->Each((DoToObjectType) &CReplaceOnce::ReplaceOnce,&aCReplaceOnce);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TDialogView::Initialize(void) // override
{
inherited::Initialize();
#if qDebug
if (!gUDialogInitialized)
{
ProgramBreak("InitUDialog must be called before creating a Dialog View.");
Failure(noErr, 0);
}
#endif
fDefaultItem = kNoIdentifier;
fCancelItem = kNoIdentifier;
fDismisser = kNoIdentifier;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TDialogView::IDialogView(TDocument* itsDocument,
TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
const IDType itsDefItemID,
const IDType itsCancelItemID)
{
#if qDebug
if (!gUDialogInitialized)
{
ProgramBreak("InitUDialog must be called before creating a Dialog View.");
Failure(noErr, 0);
}
#endif
this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fDefaultItem = itsDefItemID;
fCancelItem = itsCancelItemID;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TDialogView::IRes(TDocument* itsDocument,
TView* itsSuperView,
Ptr& itsParams) // override
{
#if qDebug
if (!gUDialogInitialized)
{
ProgramBreak("InitUDialog must be called before creating a Dialog View.");
Failure(noErr, 0);
}
#endif
inherited::IRes(itsDocument, itsSuperView, itsParams);
DialogViewTemplate& templateData = (DialogViewTemplate&) *itsParams;
fDefaultItem = templateData.defaultItem;
fCancelItem = templateData.cancelItem;
OffsetPtr(itsParams, sizeof(DialogViewTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TDialogView::Clone(void) // override
{
TDialogView* aClonedDialogView;
aClonedDialogView = (TDialogView*)(inherited::Clone());
return aClonedDialogView;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TDialogView::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
DialogViewTemplate& templateData =
(DialogViewTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(DialogViewTemplate)));
templateData.defaultItem = fDefaultItem;
templateData.cancelItem = fCancelItem;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TDialogView::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'dlog'; gWResType = "TDialogView";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TDialogView::Free(void) // override
{
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TDialogView::CanDismiss(const IDType dismissing)
{
TView* dismissingView;
Boolean successful;
// First, make sure the view initiating the the dismissal, if any, is enabled.
if (((long) dismissing) != ((long) kNoIdentifier))
dismissingView = FindSubView(dismissing);
else
dismissingView = NULL; // no dismissing view
// Thanks Tommi GESSL
successful = (dismissingView == NULL) || (dismissingView->IsEnabled());
if (successful) /* test only we haven´t failed */
/* Now, if we're not cancelling, make sure the current edit text is valid and
return false if it isn't.*/
if ( ( (long) fCancelItem == (long) kNoIdentifier ) || (dismissing != fCancelItem) )
{
this->DoSelectEditText(NULL, False); // Attempt to deselect current edit text
return (this->GetCurrentEditText() == NULL); // Successful only if it was deselected
}
else
return (successful);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TDialogView::Close(void) // override
{
if (((long)fDismisser) == ((long)kNoIdentifier))
this->DismissDialog(kNoIdentifier);
inherited::Close();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TDialogView::DeselectCurrentEditText(void)
{
TEditText* currentEditText;
Boolean result;
result = TRUE;
currentEditText = this->GetCurrentEditText();
if ((currentEditText != NULL) && (currentEditText->fTEView != NULL))
{
result = (currentEditText->fTEView->WillingToResignTarget() == kValidValue);
this->BeTarget();
}
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TDialogView::DismissDialog(const IDType dismisser)
{
TWindow* itsWindow;
itsWindow = this->GetWindow();
if (!itsWindow->IsDismissed())
if (this->CanDismiss(dismisser))
{
itsWindow->Dismiss();
fDismisser = dismisser;
}
else
Failure(noErr, 0); // Silent failure
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::HandleEvent(EvtNumber eventNumber,
TEvtHandler* source,
TEvent* event) // override
{
switch (eventNumber)
{
case mEditTextHit:
#if qDebug
if (! source->IsMemberClass(GetClassIDFromName("TEditText")))
ProgramBreak("Got mEditTextHit on non-TEditText view.");
else
#endif
//!!!RCR
#if FALSE
DoSelectEditText((TEditText*) source), False);
#endif
break;
default:
if ( source->IsMemberClass(GetClassIDFromName("TControl")) && ((TControl*) source)->fDismissesDialog )
DismissDialog(((TView*) source)->fIdentifier) ;
else
inherited::HandleEvent(eventNumber,source,event);
break;
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::DoCommandKey(TDeviceEvent* event) // override
{
TView* cancelView;
//!!! this needs internationalization
if ( this->IsEnabled() && event->fCharacter == '.' && ( (long) fCancelItem != (long) kNoIdentifier) )
{
cancelView = this->FindSubView(fCancelItem);
if (cancelView != NULL)
{
if ( cancelView->IsMemberClass(GetClassIDFromName("TControl")) )
cancelView->HandleEvent(((TControl*) cancelView)->fDefChoice, this,NULL);
else
cancelView->HandleEvent(mCancelKey, this,NULL);
}
else
this->HandleEvent(mCancelKey, this,NULL);
}
else
inherited::DoCommandKey(event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::DoKeyCommand(TDeviceEvent* event) // override
{
TView* defaultView;
TView* cancelView;
// If we get this far, nobody's handled the Tab, Enter, or Return keys, so we will
if (this->IsEnabled())
{
switch (event->fCharacter)
{
case chEscape:
if (event->fKeyCode == kClearVirtualCode) // esc double for two different keys!
inherited::DoKeyCommand(event);
else if (((long)fCancelItem) != ((long)kNoIdentifier))
{
cancelView = FindSubView(fCancelItem);
if (cancelView != NULL)
{
if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
cancelView->HandleEvent( ((TControl*) cancelView)->fDefChoice, cancelView, NULL);
else
cancelView->HandleEvent(mCancelKey, cancelView, NULL);
}
else
this->HandleEvent(mCancelKey, this, NULL);
}
else
inherited::DoKeyCommand(event);
break;
case chTab:
TabTarget(event->fShiftKey,TRUE);
break;
case chEnter:
case chReturn:
if ( (long) fDefaultItem != (long) kNoIdentifier )
{
defaultView = FindSubView(fDefaultItem);
if (defaultView != NULL)
{
if (defaultView->IsMemberClass(GetClassIDFromName("TControl")))
defaultView->HandleEvent( ((TControl*) defaultView)->fDefChoice, defaultView, NULL);
else
defaultView->HandleEvent(mDefaultKey, defaultView, NULL);
}
else
this->HandleEvent(mDefaultKey, this, NULL);
}
else
inherited::DoKeyCommand(event);
break;
default:
inherited::DoKeyCommand(event);
}
}
else
inherited::DoKeyCommand(event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::DoSelectEditText(TEditText* theEditText,
Boolean selectChars)
{
if (theEditText != this->GetCurrentEditText()) // If we're not editing this view…
{
if (theEditText == NULL)
this->BeTarget(); // Set the window's target to self
else
{
if (theEditText->IsEnabled())
theEditText->StartEdit(selectChars);
#if qDebug
else
ProgramBreak("Attempt to select a disabled edit text view")
#endif
;
}
}
else
if (selectChars && (theEditText != NULL)) // Make sure all the chars are selected.
theEditText->SetSelection(0, MAXINT, kRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
//RCR Iteration object for EachEditText
typedef pascal void (*DoToViewType) (TView* , void* staticLink) ;
typedef pascal void (*DoToEditTextType) (TEditText* , void* staticLink) ;
class CCheckSubView
{
const void*& fStaticLink;
const DoToEditTextType& fDoToEditText;
public:
// Constructor
CCheckSubView(const DoToEditTextType DoToEditText,void* staticLink)
:fDoToEditText (DoToEditText),fStaticLink (staticLink) {};
pascal void CheckSubView(TView* theSubView);
};
#pragma segment DlgRes
pascal void CCheckSubView::CheckSubView(TView* theSubView)
{
if (theSubView->IsMemberClass(GetClassIDFromName("TEditText")))
fDoToEditText( (TEditText*) theSubView, fStaticLink);
else
{
CCheckSubView aCCheckSubView(fDoToEditText,fStaticLink);
theSubView->EachSubView((DoToViewType) &CCheckSubView::CheckSubView,&aCCheckSubView);
}
};
#pragma segment DlgRes
pascal void TDialogView::EachEditText(DoToEditTextType DoToEditText, void *staticLink)
{
CCheckSubView aCCheckSubView(DoToEditText,staticLink);
this->EachSubView((DoToViewType) &CCheckSubView::CheckSubView,&aCCheckSubView);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TEditText* TDialogView::GetCurrentEditText(void)
{
TEvtHandler* currentTarget;
TWindow* myWindow;
TEditText* result;
//!!!RCR Needs work
result = NULL;
myWindow = this->GetWindow();
if (myWindow != NULL)
currentTarget = myWindow->GetTarget();
else
currentTarget = NULL;
if ((currentTarget != NULL) && currentTarget->IsMemberClass(GetClassIDFromName("TDialogTEView")) )
result = ((TDialogTEView*) currentTarget)->fEditText;
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TView* TDialogView::GetDialogView(void) // override
{
return this;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAOpen
pascal void TDialogView::DoOpen(void)
{
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAOpen
pascal void TDialogView::Open(void) // override
{
fDismisser = kNoIdentifier;
DoOpen();
inherited::Open();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal IDType TDialogView::PoseModally(void)
{
TWindow* itsWindow;
itsWindow = this->GetWindow();
if (itsWindow != NULL)
{
itsWindow->PoseModally();
return fDismisser;
}
else
return kNoIdentifier;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::SelectEditText(const IDType itsIdentifier,
Boolean selectChars)
{
TView* aSubView;
aSubView = FindSubView(itsIdentifier);
if ((aSubView != NULL) && aSubView->IsMemberClass(GetClassIDFromName("TEditText")) )
DoSelectEditText((TEditText*) aSubView, selectChars);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogView::SurveyEditText(TEditText* first,
TEditText* last,
TEditText* next,
TEditText* previous)
/*RCR Would like to remove this method entirely
pascal void Survey(TEditText theEditText)
{
if (theEditText.IsEnabled && theEditText->IsShown())
{
if (first == NULL)
first = theEditText;
last = theEditText;
//RCR if (theEditText == this->GetCurrentEditText())
foundCurrent = TRUE
else if (foundCurrent && (next == NULL))
next = theEditText;
if (!foundCurrent)
previous = theEditText;
}
}
*/
{
/* Boolean foundCurrent;
foundCurrent = False;
next = NULL;
previous = NULL;
first = NULL;
last = NULL;
EachEditText(Survey);
if (next == NULL)
next = first;
if (previous == NULL)
previous = last;
*/ }
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TDialogView::Fields(TObject* obj) // override
{
obj->DoToField("TDialogView", NULL, bClass);
obj->DoToField("fDefaultItem", &fDefaultItem, bIDType);
obj->DoToField("fCancelItem", &fCancelItem, bIDType);
obj->DoToField("fDismisser", &fDismisser, bIDType);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TButton::Initialize(void) // override
{
inherited::Initialize();
fDefChoice = mButtonHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TButton::IButton(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
const Str255& itsLabel)
{
this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0,
((pushButProc) |useWFont));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TButton::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
VRect itsArea;
inherited::IRes(NULL, itsSuperView, itsParams);
this->ControlArea(itsArea);
CreateCMgrControl(itsArea, ((ButtonTemplatePtr) itsParams)->itsLabel, 0, 0, 0, ((pushButProc) |useWFont));
OffsetPtrWStr(itsParams, sizeof(ButtonTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TButton::Clone(void) // override
{
TButton* aClonedButton;
aClonedButton = (TButton*)(inherited::Clone());
return aClonedButton;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TButton::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
Str255 theLabel;
inherited::WRes(theResource, itsParams);
this->GetText(theLabel);
ButtonTemplate& templateData =
(ButtonTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(ButtonTemplate),
theLabel.Length()));
// templateData.itsLabel = theLabel;
CopyStr255(theLabel, PRStr(templateData.itsLabel));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TButton::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'butn'; gWResType = "TButton";
WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TButton::HandleEvent(EvtNumber eventNumber,
TEvtHandler* source,
TEvent* event) // override
{
if ( (eventNumber == mButtonHit) && (source != this) && this->IsEnabled() )
this->Flash();
inherited::HandleEvent(eventNumber,source,event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TButton::Fields(TObject* obj) // override
{
obj->DoToField("TButton", NULL, bClass);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCheckBox::Initialize(void) // override
{
inherited::Initialize();
fDefChoice = mCheckBoxHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCheckBox::ICheckBox(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
const Str255& itsLabel,
Boolean isTurnedOn)
{
this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
((checkBoxProc) |useWFont));
this->SetState(isTurnedOn, kDontRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCheckBox::IRes(TDocument* /* itsDocument */,
TView* itsSuperView,
Ptr& itsParams) // override
{
VRect itsArea;
inherited::IRes(NULL, itsSuperView, itsParams);
ControlArea(itsArea);
CreateCMgrControl(itsArea, ((CheckBoxTemplatePtr) itsParams)->itsLabel, (long)(this->IsOn()), 0, 1, ((checkBoxProc) |useWFont));
OffsetPtrWStr(itsParams, sizeof(CheckBoxTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TCheckBox::Clone(void) // override
{
TCheckBox* aClonedCheckBox;
aClonedCheckBox = (TCheckBox*)(inherited::Clone());
return aClonedCheckBox;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TCheckBox::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
Str255 theLabel;
inherited::WRes(theResource, itsParams);
this->GetText(theLabel);
CheckBoxTemplate& templateData =
(CheckBoxTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(CheckBoxTemplate),
theLabel.Length()));
templateData.isOn = this->IsOn();
// templateData.itsLabel = theLabel;
CopyStr255(theLabel, PRStr(templateData.itsLabel));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TCheckBox::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'chkb'; gWResType = "TCheckBox";
WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCheckBox::HandleEvent(EvtNumber eventNumber,
TEvtHandler* source,
TEvent* event) // override
{
if (eventNumber == mCheckBoxHit)
this->Toggle(kRedraw);
inherited::HandleEvent(eventNumber,source,event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TCheckBox::IsOn(void)
{
return (this->GetLongVal() != 0);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCheckBox::SetState(Boolean state,
Boolean redraw)
{
this->SetLongVal((long) state, redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCheckBox::Toggle(Boolean redraw)
{
this->SetLongVal( (long) (! this->IsOn()), redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCheckBox::ToggleIf(Boolean matchState,
Boolean redraw)
{
if (this->IsOn() == matchState)
this->SetLongVal( (long) (! this->IsOn()), redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TCheckBox::Fields(TObject* obj) // override
{
obj->DoToField("TCheckBox", NULL, bClass);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TRadio::Initialize(void) // override
{
inherited::Initialize();
fDefChoice = mRadioHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TRadio::IRadio(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
const Str255& itsLabel,
Boolean isTurnedOn)
{
this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
((radioButProc) |useWFont));
this->SetState(isTurnedOn, kDontRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TRadio::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
VRect itsArea;
inherited::IRes(NULL, itsSuperView, itsParams);
this->ControlArea(itsArea);
this->CreateCMgrControl(itsArea, ((RadioTemplatePtr) itsParams)->itsLabel, (long) (this->IsOn()), 0, 1, ((radioButProc) |useWFont));
OffsetPtrWStr(itsParams, sizeof(RadioTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TRadio::Clone(void) // override
{
TRadio* aClonedRadio;
aClonedRadio = (TRadio*) (inherited::Clone());
return aClonedRadio;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TRadio::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
Str255 theLabel;
inherited::WRes(theResource, itsParams);
this->GetText(theLabel);
RadioTemplate& templateData =
(RadioTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(RadioTemplate),
theLabel.Length()));
templateData.isOn = this->IsOn();
// templateData.itsLabel = theLabel;
CopyStr255(theLabel, PRStr(templateData.itsLabel));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TRadio::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'radb'; gWResType = "TRadio";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TRadio::HandleEvent(EvtNumber eventNumber,
TEvtHandler* source,
TEvent* event) // override
{
if ((eventNumber == mRadioHit) && !this->IsOn())
this->Toggle(kRedraw);
inherited::HandleEvent(eventNumber,source,event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TRadio::IsOn(void)
{
return (this->GetLongVal() != 0);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TRadio::SetState(Boolean state,
Boolean redraw)
{
this->SetLongVal( (long)(state), redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TRadio::Toggle(Boolean redraw)
{
this->SetLongVal((long) (! this->IsOn()), redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TRadio::ToggleIf(Boolean matchState,
Boolean redraw)
{
if (this->IsOn() == matchState)
this->SetLongVal((long) (! this->IsOn()), redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TRadio::Fields(TObject* obj) // override
{
obj->DoToField("TRadio", NULL, bClass);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCluster::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fRsrcID = kNoResource;
fIndex = 0; // ??? Is there a constant for this
fDefChoice = mClusterHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCluster::ICluster(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID,
short itsIndex)
{
Str255 aString;
FailInfo fi;
this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fRsrcID = itsRsrcID;
fIndex = itsIndex;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure() )
{
GetIndString(aString, fRsrcID, fIndex);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
this->SetLabel(aString, kDontRedraw);
}
this->SetEnable(False); // Default is not to enable hit testing
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TCluster::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
inherited::IRes(NULL, itsSuperView, itsParams);
this->SetLabel(((ClusterTemplatePtr) itsParams)->itsLabel, kDontRedraw);
OffsetPtrWStr(itsParams, sizeof(ClusterTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TCluster::Clone(void) // override
{
TCluster* aClonedCluster;
Str255 theLabel;
aClonedCluster = (TCluster*) (inherited::Clone());
aClonedCluster->fDataHandle = NULL;
this->GetLabel(theLabel);
aClonedCluster->SetLabel(theLabel, kDontRedraw);
return aClonedCluster;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TCluster::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
Str255 theLabel;
inherited::WRes(theResource, itsParams);
this->GetLabel(theLabel);
ClusterTemplate& templateData =
(ClusterTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(ClusterTemplate),
theLabel.Length()));
// templateData.itsLabel = theLabel;
CopyStr255(theLabel, PRStr(templateData.itsLabel));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TCluster::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'clus'; gWResType = "TCluster";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TCluster::Free(void) // override
{
this->ReleaseLabel();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
//RCR Iteration object for ResetRadios
class CResetRadios
{
const TEvtHandler*& fSource;
public:
// Constructor
CResetRadios(const TEvtHandler*& source):
fSource (source) {};
pascal void ResetRadios(TView* aView);
};
pascal void CResetRadios::ResetRadios(TView* aView)
{
if (aView->IsMemberClass(GetClassIDFromName("TRadio")) // If the subview is a TRadio, and…
&& (aView != fSource)) // …it's not the calling radio…
((TRadio*) aView)->SetState(False, kRedraw); // …set it off and redraw it
};
pascal void TCluster::HandleEvent(EvtNumber eventNumber,
TEvtHandler* source,
TEvent* event) // override
{
if ((eventNumber == mRadioHit) && /* If we got this far, a radio's changed
state */
(((TView*) source)->fSuperView == this)) // Only worry about it if it's our subview!
{
CResetRadios aCResetRadios(source);
EachSubView((DoToViewType) &CResetRadios::ResetRadios,&aCResetRadios); // Reset everybody except the calling radio
}
inherited::HandleEvent(eventNumber,source,event);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCluster::Draw(const VRect& area) // override
{
short theFontHeight;
VCoordinate theFrameTop;
VRect theFrame;
Rect theQDFrame;
RGBColor oldColor;
TextStyle aTextStyle;
FontInfo theFontInfo;
if (fDataHandle != NULL)
{
PenNormal(); // Normalcy in most things
PenSize(fPenSize.h, fPenSize.v); // PenSize(2, 2);
GetIfColor(oldColor); // Save the original pen color
aTextStyle = fTextStyle;
GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
this->ControlArea(theFrame); // Get the control's extent
theFrameTop = theFrame.top + ((theFontHeight) >> 1);
InsetVRect(theFrame, fPenSize.h + 1, fPenSize.v + 1); // Inset the frame a little
theFrame.top = theFrameTop; // Bump top so it cuts label in half
this->ViewToQDRect(theFrame, theQDFrame);
FrameRect(theQDFrame); // Draw the frame
this->DrawLabel(area); // Draw the label
SetIfColor(oldColor);
}
inherited::Draw(area); // Let parents have a chance to draw too
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TCluster::DrawLabel(const VRect& area)
{
TextStyle aTextStyle;
Str255 theText;
VRect labelRect;
Rect labelQDRect;
VRect dstRect;
FontInfo theFontInfo;
aTextStyle = fTextStyle;
SetPortTextStyle(aTextStyle); // Install the object's TextStyle
this->GetLabel(theText); // retrieve the label
MAReplaceText(theText);
SetVRect(labelRect, 16, 0, StringWidth(theText) + 8 + 16, MAGetFontInfo(theFontInfo));
if (SectVRect(area, labelRect, dstRect))
{
this->ViewToQDRect(labelRect, labelQDRect);
MATextBox(Ptr(((long)&theText) + 1), theText.Length(), labelQDRect, teCenter, kNoAutoWrap,
NULL, kEraseFirst, kNoSpaceForCaret);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
typedef Str255* RCRStringPtr;
typedef RCRStringPtr* RCRStringHandle;
pascal void TCluster::GetLabel(Str255& theLabel)
{
if (fDataHandle != NULL)
CopyStr255( (**((RCRStringHandle) fDataHandle)), (Ptr)&theLabel);
else
theLabel = "";
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TCluster::ReleaseLabel(void)
{
fDataHandle = (StringHandle) DisposeIfHandle( (Handle) fDataHandle);
fRsrcID = kNoResource;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean FindRadio(TView* aView,void* /* staticLink */)
{
return ( aView->IsMemberClass(GetClassIDFromName("TRadio")) && ((TRadio*) aView)->IsOn() ) ;
}
pascal IDType TCluster::ReportCurrent(void)
{
TView* rView;
rView = this->FirstSubViewThat(FindRadio,this);
if (rView != NULL)
return (rView->fIdentifier);
else
return kNoIdentifier;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TCluster::SetLabel(const Str255& theLabel,
Boolean redraw)
{
this->ReleaseLabel();
if (theLabel != "")
{
fDataHandle = NewString(theLabel);
if (MemError() != noErr)
fDataHandle = NULL;
}
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TCluster::Fields(TObject* obj) // override
{
Str255 aString;
obj->DoToField("TCluster", NULL, bClass);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fIndex", &fIndex, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
if (fDataHandle != NULL)
{
aString = (**((RCRStringHandle) fDataHandle));
obj->DoToField("**fDataHandle", &aString, bString);
}
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TIcon::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fIsColor = kPreferColor;
fPreferColor = kPreferColor;
fRsrcID = kNoResource;
fDefChoice = mIconHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TIcon::IIcon(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID,
Boolean preferColor)
{
FailInfo fi;
Handle itsRsrcHandle;
SignedByte savedState;
IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fPreferColor = preferColor;
fIsColor = preferColor;
fRsrcID = itsRsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure() )
{
if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
{
// make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
itsRsrcHandle = GetResource('cicn', fRsrcID);
if (itsRsrcHandle != NULL)
{
savedState = HGetState(itsRsrcHandle);
HNoPurge(itsRsrcHandle);
}
fDataHandle = Handle(GetCIcon(fRsrcID));
// restore the state of the 'cicn' resource
if (itsRsrcHandle != NULL)
HSetState(itsRsrcHandle, savedState);
}
if (fDataHandle == NULL)
{
fDataHandle = GetIcon(fRsrcID);
if (fDataHandle != NULL)
fIsColor = !kPreferColor; // Either can't or won't
}
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
this->SetEnable(False); // Default is to not enable hit testing }
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TIcon::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
FailInfo fi;
Handle itsRsrcHandle;
SignedByte savedState;
fDataHandle = NULL;
inherited::IRes(NULL, itsSuperView, itsParams);
IconTemplate& templateData = (IconTemplate&) *itsParams;
fPreferColor = templateData.preferColor;
fIsColor = templateData.preferColor;
fRsrcID = templateData.rsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure() )
{
if ( (fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
{
// make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
itsRsrcHandle = GetResource('cicn', fRsrcID);
if (itsRsrcHandle != NULL)
{
savedState = HGetState(itsRsrcHandle);
HNoPurge(itsRsrcHandle);
}
fDataHandle = Handle(GetCIcon(fRsrcID));
// restore the state of the 'cicn' resource
if (itsRsrcHandle != NULL)
HSetState(itsRsrcHandle, savedState);
}
if (fDataHandle == NULL)
{
fDataHandle = GetIcon(fRsrcID);
if (fDataHandle != NULL)
fIsColor = !kPreferColor; // Either can't or won't
}
// Don't die because resource not found - just return NULL handle
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
OffsetPtr(itsParams, sizeof(IconTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TIcon::Clone(void) // override
{
TIcon* aClonedIcon;
Handle aHandle;
OSErr err;
Handle itsRsrcHandle;
SignedByte savedState;
aClonedIcon = (TIcon*) (inherited::Clone());
aClonedIcon->fDataHandle = NULL;
if (fDataHandle != NULL)
{
if (fIsColor)
{
// make the 'cicn' resource non-purgeable, so the Toolbox doesn't die
itsRsrcHandle = GetResource('cicn', fRsrcID);
if (itsRsrcHandle != NULL)
{
savedState = HGetState(itsRsrcHandle);
HNoPurge(itsRsrcHandle);
}
aClonedIcon->fDataHandle = Handle(GetCIcon(fRsrcID));
// restore the state of the 'cicn' resource
if (itsRsrcHandle != NULL)
HSetState(itsRsrcHandle, savedState);
}
else
{
aHandle = fDataHandle;
err = HandToHand(aHandle);
if (err != noErr)
FailNIL(aHandle);
aClonedIcon->fDataHandle = aHandle;
}
}
return aClonedIcon;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TIcon::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
IconTemplate& templateData =
(IconTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(IconTemplate)));
templateData.preferColor = fPreferColor;
#if qDebug
if (fRsrcID == kNoResource)
cout << "Tried to write TIcon with no resource ID.\n";
#endif
templateData.rsrcID = fRsrcID;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TIcon::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'icon'; gWResType = "TIcon";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TIcon::Free(void) // override
{
this->ReleaseIcon();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TIcon::Draw(const VRect& area) // override
{
SignedByte oldState;
VRect theRect;
Rect theQDRect;
PixMap aPixMap;
BitMapPtr aBitMapPtr;
Rect srcRect;
if (fDataHandle != NULL)
{
if (IsAResource(fDataHandle))
LoadResource(fDataHandle);
if ((*fDataHandle) != NULL) // If there's room for the icon…
{
PenNormal(); // NECESSARY?
ControlArea(theRect);
ViewToQDRect(theRect, theQDRect);
oldState = HGetState(fDataHandle);
HNoPurge(fDataHandle);
HLock(fDataHandle);
if (fIsColor)
{
// We can't use PlotCIcon here because it can't be written to a picture
// and when WriteToDeskScrap is called, the icon is plotted on the
// desktop rather than in the picture. So instead, pick apart the color
// icon handle and use copybits, ignoring the mask.
aPixMap = (**((CIconHandle) fDataHandle)).iconPMap;
HLock((**((CIconHandle) fDataHandle )).iconData);
aPixMap.baseAddr = *((**((CIconHandle) fDataHandle)).iconData);
srcRect = aPixMap.bounds;
aBitMapPtr = (BitMapPtr) &aPixMap;
CopyBits((*aBitMapPtr), qd.thePort->portBits, srcRect, theQDRect, srcCopy, NULL);
HUnlock((**((CIconHandle) fDataHandle )).iconData);
}
else
PlotIcon(&theQDRect, fDataHandle);
HSetState(fDataHandle, oldState);
}
}
inherited::Draw(area);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TIcon::ReleaseIcon(void)
{
fRsrcID = kNoResource;
if (fDataHandle != NULL)
{
if (fIsColor)
DisposCIcon((CIconHandle) fDataHandle);
else
HPurge(fDataHandle);
fDataHandle = NULL;
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TIcon::SetIcon(Handle theIcon,
Boolean redraw)
{
short theID;
ResType theType;
Str255 name;
this->ReleaseIcon();
if (GetHandleSize(theIcon) != 128)
fPreferColor= TRUE;
else
fPreferColor= FALSE;
fDataHandle = theIcon;
// get the rsrc id
GetResInfo(theIcon, theID, theType, name);
if (ResError() == noErr)
fRsrcID = theID;
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TIcon::Fields(TObject* obj) // override
{
obj->DoToField("TIcon", NULL, bClass);
obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
obj->DoToField("fIsColor", &fIsColor, bBoolean);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TSmallIcon::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fRsrcID = kNoResource;
fDefChoice = mSmallIconHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TSmallIcon::ISmallIcon(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID)
{
FailInfo fi;
this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fRsrcID = itsRsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
fDataHandle = GetResource('SICN', fRsrcID);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
this->SetEnable(False); // Default is to not enable hit testing
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TSmallIcon::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
const short kReadOnlySICN = 256; // resource ID of small slashed pencil icon
FailInfo fi;
inherited::IRes(NULL, itsSuperView, itsParams);
// fRsrcID = SmallIconTemplatePtr(itsParams)->rsrcID;
fRsrcID = kReadOnlySICN; // until MacApp 2.1.0.1
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
fDataHandle = GetResource('SICN', fRsrcID);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
// OffsetPtr(itsParams, sizeof(SmallIconTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TSmallIcon::Clone(void) // override
{
TSmallIcon* aClonedSmallIcon;
Handle aHandle;
OSErr err;
aClonedSmallIcon = (TSmallIcon*)(inherited::Clone());
aHandle = aClonedSmallIcon->fDataHandle;
if (aHandle != NULL)
{
err = HandToHand(aHandle);
if (err != noErr)
FailNIL(aHandle);
aClonedSmallIcon->fDataHandle = aHandle;
}
return aClonedSmallIcon;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TSmallIcon::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
SmallIconTemplate& templateData =
(SmallIconTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(SmallIconTemplate)));
#if qDebug
if (fRsrcID == kNoResource)
cout << "Tried to write TSmallIcon with no resource ID.\n";
#endif
templateData.rsrcID = fRsrcID;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TSmallIcon::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'SICN'; gWResType = "TSmallIcon";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TSmallIcon::Draw(const VRect& area) // override
{
SignedByte oldState;
VRect theRect;
Rect theQDRect;
BitMap srcBits;
GrafPtr port;
#if qDebug
this->AssumeFocused();
#endif
if (fDataHandle != NULL)
{
if (IsAResource(fDataHandle))
LoadResource(fDataHandle);
if ((*fDataHandle) != NULL) // If there's room for the small icon…
{
this->ControlArea(theRect);
this->ViewToQDRect(theRect, theQDRect);
oldState = HGetState(fDataHandle);
HNoPurge(fDataHandle);
// construct a source BitMap
srcBits.baseAddr = (*fDataHandle);
srcBits.rowBytes = 2;
SetRect(srcBits.bounds, 0, 0, 16, 16);
GetPort(port);
CopyBits(srcBits, port->portBits, srcBits.bounds, theQDRect, srcCopy, NULL);
HSetState(fDataHandle, oldState);
}
}
inherited::Draw(area);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TSmallIcon::ReleaseSmallIcon(void)
{
fRsrcID = kNoResource;
if (fDataHandle != NULL)
HPurge(fDataHandle);
fDataHandle = NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TSmallIcon::SetSmallIcon(short theSmallIcon,
Boolean redraw)
{
FailInfo fi;
this->ReleaseSmallIcon();
if (! fi.CatchFailure())
{
fDataHandle = GetResource('SICN', theSmallIcon);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
fRsrcID = theSmallIcon;
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TSmallIcon::Fields(TObject* obj) // override
{
obj->DoToField("TSmallIcon", NULL, bClass);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPattern::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fPreferColor = kPreferColor;
fIsColor = kPreferColor;
fRsrcID = kNoResource;
fDefChoice = mPatternHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPattern::IPattern(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID,
Boolean preferColor)
{
FailInfo fi;
this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fPreferColor = preferColor;
fIsColor = preferColor;
fRsrcID = itsRsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
fDataHandle = Handle(GetPixPat(fRsrcID));
if (fDataHandle == NULL)
{
fDataHandle = Handle(GetPattern(fRsrcID));
if (fDataHandle != NULL)
fIsColor = !kPreferColor; // Either can't or won't
}
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
this->SetEnable(False); // Default is to not enable hit testing
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPattern::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
FailInfo fi;
inherited::IRes(NULL, itsSuperView, itsParams);
PatternTemplate& templateData = (PatternTemplate&) *itsParams;
fPreferColor = templateData.preferColor;
fIsColor = templateData.preferColor;
fRsrcID = templateData.rsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
fDataHandle = (Handle) GetPixPat(fRsrcID);
if (fDataHandle == NULL)
{
fDataHandle = (Handle) GetPattern(fRsrcID);
if (fDataHandle != NULL)
fIsColor = !kPreferColor; // Either can't or won't
}
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
OffsetPtr(itsParams, sizeof(PatternTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TPattern::Clone(void) // override
{
TPattern* aClonedPattern;
FailInfo fi;
Handle aHandle;
OSErr err;
aClonedPattern = (TPattern*)(inherited::Clone());
if (fDataHandle != NULL)
{
if (! fi.CatchFailure())
{
if (fIsColor)
aClonedPattern->fDataHandle = (Handle) GetPixPat(fRsrcID);
else
{
aHandle = fDataHandle;
err = HandToHand(aHandle);
aClonedPattern->fDataHandle = aHandle;
}
FailNIL(aClonedPattern->fDataHandle);
fi.Success();
}
else
{
aClonedPattern->Free();
fi.ReSignal();
}
}
return aClonedPattern;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TPattern::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
PatternTemplate& templateData =
(PatternTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(PatternTemplate)));
templateData.preferColor = fPreferColor;
#if qDebug
if (fRsrcID == kNoResource)
cout << "Tried to write TPattern with no resource ID.\n";
#endif
templateData.rsrcID = fRsrcID;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TPattern::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'patn'; gWResType = "TPattern";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TPattern::Free(void) // override
{
this->ReleasePattern();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TPattern::Draw(const VRect& area) // override
{
Boolean wasLocked;
VRect theRect;
Rect theQDRect;
if (fDataHandle != NULL)
{
if (IsAResource(fDataHandle) && !fIsColor) // Pixpat handles != resource handles
LoadResource(fDataHandle);
if ((*fDataHandle) != NULL) // If there's room for the pattern…
{
PenNormal(); // NECESSARY?
this->ControlArea(theRect);
this->ViewToQDRect(theRect, theQDRect);
wasLocked = IsHandleLocked(fDataHandle); // Remember current lock state
if (!wasLocked)
HLock(fDataHandle); // Because FillRect may move memory
if (fIsColor)
FillCRect(theQDRect, (PixPatHandle) fDataHandle );
else
FillRect(theQDRect, **((PatHandle) fDataHandle));
if (!wasLocked)
HUnlock(fDataHandle); // restore handle's unlocked state
}
}
inherited::Draw(area);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TPattern::ReleasePattern(void)
{
fRsrcID = kNoResource;
if (fDataHandle != NULL)
{
if (fIsColor)
DisposPixPat((PixPatHandle) fDataHandle);
else
HPurge(fDataHandle);
fDataHandle = NULL;
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TPattern::SetPattern(Handle thePattern,
Boolean redraw)
{
short theID;
ResType theType;
Str255 name;
this->ReleasePattern();
fDataHandle = thePattern;
// get the rsrc id for non-color patterns (color pattern handles aren't resource handles)
if (!fIsColor)
{
GetResInfo(thePattern, theID, theType, name);
if (ResError() == noErr)
fRsrcID = theID;
}
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TPattern::Fields(TObject* obj) // override
{
obj->DoToField("TPattern", NULL, bClass);
obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
obj->DoToField("fIsColor", &fIsColor, bBoolean);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPicture::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fRsrcID = kNoResource;
fDefChoice = mPictureHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPicture::IPicture(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID)
{
FailInfo fi;
this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fRsrcID = itsRsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
fDataHandle = GetPicture(fRsrcID);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
this->SetEnable(False); // Default is to not enable hit testing
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TPicture::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
FailInfo fi;
fDataHandle = NULL;
inherited::IRes(NULL, itsSuperView, itsParams);
fRsrcID = ((PictureTemplatePtr) itsParams)->rsrcID;
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
fDataHandle = GetPicture(fRsrcID);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
}
OffsetPtr(itsParams, sizeof(PictureTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TPicture::Clone(void) // override
{
TPicture* aClonedPicture;
FailInfo fi;
aClonedPicture = (TPicture*) (inherited::Clone());
if (fDataHandle != NULL)
{
aClonedPicture->fDataHandle = NULL;
if (! fi.CatchFailure())
{
aClonedPicture->fDataHandle = GetPicture(fRsrcID);
FailResError();
fi.Success();
}
else
{
aClonedPicture->Free();
fi.ReSignal();
}
}
return aClonedPicture;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TPicture::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
PictureTemplate& templateData =
(PictureTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(PictureTemplate)));
#if qDebug
if (fRsrcID == kNoResource)
cout << "Tried to write TPicture with no resource ID.\n";
#endif
templateData.rsrcID = fRsrcID;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TPicture::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'pict'; gWResType = "TPicture";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TPicture::Free(void) // override
{
this->ReleasePicture();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TPicture::Draw(const VRect& area) // override
{
SignedByte oldState;
VRect theRect;
Rect theQDRect;
if (fDataHandle != NULL)
{
if (IsAResource( (Handle) fDataHandle))
LoadResource((Handle) fDataHandle);
if (*fDataHandle != NULL) // If there's room for the picture…
{
this->ControlArea(theRect);
this->ViewToQDRect(theRect, theQDRect);
oldState = HGetState( (Handle) fDataHandle);
HNoPurge((Handle) fDataHandle);
PenNormal(); // ??? NECESSARY ???
DrawPicture(fDataHandle, theQDRect);
HSetState((Handle) fDataHandle, oldState);
}
}
inherited::Draw(area);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TPicture::ReleasePicture(void)
{
fRsrcID = kNoResource;
if (fDataHandle != NULL)
{
HPurge((Handle) fDataHandle);
fDataHandle = NULL;
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TPicture::SetPicture(PicHandle thePicture,
Boolean redraw)
{
short theID;
ResType theType;
Str255 name;
this->ReleasePicture();
fDataHandle = thePicture;
// get the rsrc id
GetResInfo((Handle) thePicture, theID, theType, name);
if (ResError() == noErr)
fRsrcID = theID;
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TPicture::Fields(TObject* obj) // override
{
obj->DoToField("TPicture", NULL, bClass);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment TEOpen
pascal void TDialogTEView::Initialize(void) // override
{
inherited::Initialize();
fEditText = NULL; /* We don't own this reference but we don't
want an invalid one either */
fScroller = NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment TEOpen
pascal void TDialogTEView::IDialogTEView(TDocument* itsDocument,
TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHDeterminer,
SizeDeterminer itsVDeterminer,
const VRect& itsInset,
const TextStyle& itsTextStyle,
short itsJustification,
Boolean itsStyleType,
Boolean itsAutoWrap)
{
TScroller* aScroller;
this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer,
itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
aScroller = new TScroller;
aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, 0, 0,
!kWantHScrollBar, !kWantVScrollBar);
fScroller = aScroller;
fScroller->AddSubView(this);
}
//--------------------------------------------------------------------------------------------------
#pragma segment TEOpen
pascal void TDialogTEView::IRes(TDocument* itsDocument,
TView* itsSuperView,
Ptr& itsParams) // override
{
TScroller* aScroller;
inherited::IRes(itsDocument, itsSuperView, itsParams);
aScroller = new TScroller;
aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, 0, 0,
!kWantHScrollBar, !kWantVScrollBar);
fScroller = aScroller;
fScroller->AddSubView(this);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TDialogTEView::Clone(void) // override
{
TDialogTEView* aClonedDialogTEView;
aClonedDialogTEView = (TDialogTEView*) (inherited::Clone());
aClonedDialogTEView->fEditText = NULL; // no current edittext
if (aClonedDialogTEView->fScroller != NULL)
aClonedDialogTEView->fScroller = (TScroller*)(aClonedDialogTEView->fScroller->Clone());
return aClonedDialogTEView;
}
//--------------------------------------------------------------------------------------------------
#pragma segment TEClose
pascal void TDialogTEView::Free(void) // override
{
if (fScroller != NULL)
{
fScroller->RemoveSubView(this);
fScroller = (TScroller*) FreeIfObject(fScroller);
}
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TDialogTEView::Fields(TObject* obj) // override
{
obj->DoToField("TDialogTEView", NULL, bClass);
obj->DoToField("fEditText", &fEditText, bObject);
obj->DoToField("fScroller", &fScroller, bObject);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogTEView::BecomeTarget(void) // override
{
// this->InstallSelection(FALSE,TRUE);
inherited::BecomeTarget();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TDialogTEView::InstallEditText(TEditText* theEditText,
Boolean selectChars)
{
Str255 theText;
TextStyle aTextStyle;
VRect theControlArea;
VRect validExtent;
Boolean hadPendingUpdate;
if (fEditText != NULL)
{
fEditText->RemoveSubView(fScroller);
fEditText = NULL;
}
if (theEditText != NULL)
{
fControlChars = theEditText->fControlChars;
fMaxChars = theEditText->fMaxChars;
fInset = gZeroVRect;
hadPendingUpdate = theEditText->HasPendingUpdate();
SetJustification(theEditText->fJust, kDontRedraw);
ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
aTextStyle = theEditText->fTextStyle;
SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
theEditText->ControlArea(theControlArea);
theEditText->AddSubView(fScroller); // my scroller
if (fAutoWrap)
fSizeDeterminer[hSel] = sizeSuperView;
else
fSizeDeterminer[hSel] = sizeVariable; /* Let the width vary with the number of
characters */
fSuperView->Resize(theControlArea.right - theControlArea.left, theControlArea.bottom - theControlArea.top, kDontInvalidate);
fSuperView->Locate(theControlArea.left, theControlArea.top, kDontInvalidate);
theEditText->GetText(theText);
this->SetText(theText);
this->RecalcText();
this->SynchView(kDontRedraw);
this->AdjustSize();
// Make the scroller's thinking match the display that the user already sees
fScroller->fTranslation.h = 0;
switch (GetActualJustification(fJustification))
{
case teFlushDefault:
case teFlushLeft:
fScroller->fTranslation.v = 0;
break;
case teFlushRight: /* Right brain thinkers… left brain thinkers?? */
((TScroller*) fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
break;
case teCenter:
fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
break;
}
theEditText->InvalidateFocus();
theEditText->UpdateCoordinates();
if (selectChars)
SetSelect(0, MAXINT, fHTE);
else
SetSelect(0, 0, fHTE); // Caller will set the selection.
this->BeInScroller(fScroller);
// Make my enable and my scroller's enable match my new superview
this->SetEnable(theEditText->IsEnabled());
fScroller->SetEnable(theEditText->IsEnabled());
// Revalidate my extent to eliminate the flicker created by resizing the scrollers
//!!! RCR && SRF Revisit this
#if FALSE
if (!hadPendingUpdate)
{
GetExtent(validExtent);
ValidateVRect(validExtent);
}
#endif
}
fEditText = theEditText;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TDialogTEView::InstallSelection(Boolean wasActive,
Boolean beActive) // override
{
/* If we're deselecting a field and it's been scrolled, invalidate it
so that it is redrawn correctly.*/
/* if (!beActive)
if (fScroller->fTranslation.v != 0)
this->ForceRedraw();
else
{
switch ( GetActualJustification(fJustification) )
{
case teFlushDefault:
case teFlushLeft:
if (fScroller->fTranslation.h != 0)
this->ForceRedraw();
break;
case teFlushRight:
if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
this->ForceRedraw();
break;
case teCenter:
if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
this->ForceRedraw();
break;
}
}
*/
inherited::InstallSelection(wasActive, beActive);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogTEView::ResignTarget(void) // override
{
inherited::ResignTarget();
/* If we're deselecting a field and it's been scrolled, invalidate it
so that it is redrawn correctly.*/
if (fScroller->fTranslation.v != 0)
this->ForceRedraw();
else
{
switch ( GetActualJustification(fJustification) )
{
case teFlushDefault:
case teFlushLeft:
if (fScroller->fTranslation.h != 0)
this->ForceRedraw();
break;
case teFlushRight:
if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
this->ForceRedraw();
break;
case teCenter:
if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
this->ForceRedraw();
break;
}
}
if (fEditText != NULL)
fEditText->StopEdit();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TDialogTEView::CantDeselect(long reason) // override
{
if (fEditText != NULL)
fEditText->CantDeselect(reason);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal long TDialogTEView::WillingToResignTarget(void) // override
{
TCommand* lastCommand;
long result;
result = 0;
if (fEditText != NULL)
{
lastCommand = this->GetLastCommand();
if ( (lastCommand != NULL) && (lastCommand->fView == this) )
this->CommitLastCommand();
result = fEditText->Validate();
}
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TDialogTEView::ComputeSize(VPoint& newSize) // override
{
inherited::ComputeSize(newSize);
if (!fAutoWrap)
switch (fSizeDeterminer[hSel])
{
case sizeVariable:
/* TTEView already computed the variable size, bump it up to at leat the scroller's
size so that the cursor is claimed for the EditText and the user can click anywhere. */
if (!fStyleType)
newSize.h = Max(fScroller->fSize.h, newSize.h);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TStaticText::Initialize(void) // override
{
inherited::Initialize();
fDataHandle = NULL;
fRsrcID = kNoResource;
fIndex = 0;
fJust = teFlushDefault; // Default to system justification
fAutoWrap = TRUE; // Default to compatibility with 2.0
fDefChoice = mStaticTextHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TStaticText::IStaticText(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
SizeDeterminer itsHSizeDet,
SizeDeterminer itsVSizeDet,
short itsRsrcID,
short itsIndex)
{
Str255 aString;
FailInfo fi;
this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
fRsrcID = itsRsrcID;
fIndex = itsIndex;
//fJust = teFlushDefault; */ /* Default to system justification
//fAutoWrap = TRUE; */ /* Default to compatibility with 2.0
if (fRsrcID != kNoResource)
{
if (! fi.CatchFailure())
{
GetIndString(aString, fRsrcID, fIndex);
FailResError();
fi.Success();
}
else
{
this->Free();
fi.ReSignal();
}
SetText(aString, kDontRedraw);
}
this->SetEnable(False); // Default is to not enable hit testing
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TStaticText::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
inherited::IRes(NULL, itsSuperView, itsParams);
//fAutoWrap = TRUE; */ /* Default to compatibility with 2.0
//fDefChoice = mStaticTextHit;
StaticTextTemplate& templateData = (StaticTextTemplate&) *itsParams;
fJust = templateData.just;
SetText(templateData.data, kDontRedraw);
OffsetPtrWStr(itsParams, sizeof(StaticTextTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TStaticText::Clone(void) // override
{
TStaticText* aClonedStaticText;
StringHandle newString;
aClonedStaticText = (TStaticText*)(inherited::Clone());
newString = aClonedStaticText->fDataHandle;
if (newString != NULL)
FailOSErr(HandToHand((Handle) newString));
aClonedStaticText->fDataHandle = newString;
return aClonedStaticText;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TStaticText::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
Str255 theText;
inherited::WRes(theResource, itsParams);
this->GetText(theText);
StaticTextTemplate& templateData =
(StaticTextTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(StaticTextTemplate),
theText.Length()));
templateData.just = fJust;
// templateData.data = theText;
CopyStr255(theText, PRStr(templateData.data));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TStaticText::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'stat'; gWResType = "TStaticText";
this->WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TStaticText::Free(void) // override
{
this->ReleaseText();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TStaticText::ChangeWrap(Boolean newAutoWrap,
Boolean redraw)
{
fAutoWrap = newAutoWrap;
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TStaticText::DoSubstitution(Str255& theText)
{
MAReplaceText(theText);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TStaticText::Draw(const VRect& area) // override
{
VRect theRect;
RGBColor oldColor;
Str255 theText;
TextStyle aTextStyle;
if (fDataHandle != NULL)
{
this->GetText(theText);
this->DoSubstitution(theText); // Make the substitution if desired
this->ControlArea(theRect);
PenNormal(); // ??? NECESSARY ???
GetIfColor(oldColor);
aTextStyle = fTextStyle;
SetPortTextStyle(aTextStyle);
this->ImageText(Ptr(((long)&theText) + 1), theText.Length(), theRect, fJust);
SetIfColor(oldColor);
}
inherited::Draw(area);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TStaticText::GetText(Str255& theText)
{
if (fDataHandle != NULL)
// theText = (*fDataHandle)^
CopyStr255((**((RCRStringHandle) fDataHandle)), (Ptr)&theText);
else
theText = "";
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TStaticText::ImageText(Ptr text,
long Length,
const VRect& box,
short just)
{
Rect qdBox;
this->ViewToQDRect(box, qdBox);
MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TStaticText::ReleaseText(void)
{
fDataHandle = (StringHandle) DisposeIfHandle( (Handle) fDataHandle);
fRsrcID = kNoResource;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TStaticText::SetJustification(short theJust,
Boolean redraw)
{
fJust = theJust;
if (redraw)
this->ForceRedraw();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TStaticText::SetText(const Str255& theText,
Boolean redraw)
{
VRect area;
Rect qdArea;
if ( (fDataHandle == NULL) || (theText != (**((RCRStringHandle) fDataHandle))) )
{
this->ReleaseText();
fDataHandle = NewString(theText);
if (MemError() != noErr)
fDataHandle = NULL;
if (redraw && this->IsDrawable())
{
this->ControlArea(area);
this->ViewToQDRect(area, qdArea);
EraseRect(qdArea);
this->Draw(area);
}
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TStaticText::Fields(TObject* obj) // override
{
Str255 aString;
obj->DoToField("TStaticText", NULL, bClass);
obj->DoToField("fRsrcID", &fRsrcID, bInteger);
obj->DoToField("fIndex", &fIndex, bInteger);
obj->DoToField("fDataHandle", &fDataHandle, bHandle);
if (fDataHandle != NULL)
{
aString = (**((RCRStringHandle) fDataHandle));
DoToField("(**fDataHandle)", &aString, bString);
}
obj->DoToField("fJust", &fJust, bInteger);
obj->DoToField("fAutoWrap", &fAutoWrap, bBoolean);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TEditText::Initialize(void) // override
{
inherited::Initialize();
fTEView = NULL;
fMaxChars = 255; // Is there a constant?
//RCR fControlChars = [chLeft, chRight, chUp, chDown, chBackspace];
fControlChars = __SetBit__(chLeft) |
__SetBit__(chRight) |
__SetBit__(chUp) |
__SetBit__(chDown) |
__SetBit__(chBackspace);
fTextStyle = gSystemStyle;
// fPenSize = Point(1,1); // …and a thin frame
fPenSize.v = 1;
fPenSize.h = 1;
SetAdornment(kFrame, kDontRedraw);
fAutoWrap = False; /* Default to compatibility with 2.0 Never
the twain shall meet.*/
fDefChoice = mEditTextHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TEditText::IEditText(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
short itsMaxChars)
{
this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
fAutoWrap = False; /* Default to compatibility with 2.0 Never
the twain shall meet.*/
fMaxChars = itsMaxChars;
//RCR fControlChars = [chLeft, chRight, chUp, chDown, chBackspace];
fControlChars = __SetBit__(chLeft) |
__SetBit__(chRight) |
__SetBit__(chUp) |
__SetBit__(chDown) |
__SetBit__(chBackspace);
fTextStyle = gSystemStyle;
Inset(3, 3, kDontRedraw); // Default is a little, teeny inset…
// fPenSize = Point(1,1); // …and a thin frame
fPenSize.v = 1;
fPenSize.h = 1;
this->SetAdornment(kFrame, kDontRedraw);
this->SetEnable(TRUE);
fDefChoice = mEditTextHit;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TEditText::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
inherited::IRes(NULL, itsSuperView, itsParams);
fAutoWrap = False; /* Default to compatibility with 2.0 Never
the twain shall meet.*/
EditTextTemplate& templateData = (EditTextTemplate&) *itsParams;
fMaxChars = templateData.maxChars;
fControlChars = templateData.controlChars;
fDefChoice = mEditTextHit;
OffsetPtr(itsParams, sizeof(EditTextTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TObject* TEditText::Clone(void) // override
{
TEditText* aClonedEditText;
aClonedEditText = (TEditText*)(inherited::Clone());
aClonedEditText->fTEView = NULL;
return aClonedEditText;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TEditText::Free(void) // override
{
this->RemoveFloatingTEView();
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TEditText::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
EditTextTemplate& templateData =
(EditTextTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(EditTextTemplate)));
templateData.maxChars = fMaxChars;
templateData.controlChars = fControlChars;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TEditText::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'edit'; gWResType = "TEditText";
WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::BecomeTarget(void) // override
{
this->StartEdit(TRUE);
inherited::BecomeTarget();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::CantDeselect(long reason)
{
Str255 aString;
if (reason != kValidValue)
{
if (reason != kErrorHandled) // go ahead and post an alert
{
if ( (reason < 1) || (reason > kNoOfDefaultReasons) )
reason = kInvalidValue;
GetIndString(aString, (short) kInvalidValueReasons, (short) reason); //!!! Note casting
ParamText(aString, "", "", "");
StdAlert(phInvalidValue);
}
aString = (**((RCRStringHandle) fDataHandle)); // Restart with previous value
this->RestartEdit(aString);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::ChangeWrap(Boolean newAutoWrap,
Boolean redraw) // override
{
inherited::ChangeWrap(newAutoWrap, redraw);
if (fTEView != NULL)
fTEView->ChangeWrap(newAutoWrap, redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TEditText::HandleMouseDown(const VPoint& theMouse,
TDeviceEvent* event,
Point& hysteresis) // override
{
return inherited::HandleMouseDown(theMouse, event, hysteresis);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TEditText::Deselect(void)
{
long validateResult;
TCommand* lastCommand;
Boolean result;
result = TRUE;
/* Commit the last command to prevent undo from applying to the wrong edit text,
and to ensure that all changes are made before validating. */
if (fTEView != NULL)
{
lastCommand = fTEView->GetLastCommand();
if ( (lastCommand != NULL) && (lastCommand->fView == fTEView))
fTEView->CommitLastCommand();
}
validateResult = this->Validate();
if (validateResult == kValidValue)
this->StopEdit();
else
{
this->CantDeselect(validateResult);
result = FALSE;
}
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::DoSubstitution(Str255& theText) // override
{
// Default action is for editable text items is not to do any substitions
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TEditText::Fields(TObject* obj) // override
{
obj->DoToField("TEditText", NULL, bClass);
obj->DoToField("fMaxChars", &fMaxChars, bInteger);
obj->DoToField("fTEView", &fTEView, bObject);
obj->DoToField("fControlChars", &fControlChars, bHexLongInt);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::GetText(Str255& theText) // override
{
Handle theChars;
short numberOfChars;
if (fTEView == NULL)
inherited::GetText(theText);
else
{
theChars = fTEView->ExtractText();
numberOfChars = (short) Min(255, GetHandleSize(theChars)); //!!! Note cast
theText[0] = ((char)(numberOfChars));
BlockMove( (Ptr)(*theChars), (Ptr)(((long)&theText) + 1), numberOfChars);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::ImageText(Ptr text,
long Length,
const VRect& box,
short just) // override
{
Rect qdBox;
if (Length >= 0)
{
this->ViewToQDRect(box, qdBox);
MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::InstallFloatingTEView(Boolean selectChars)
{
TDialogTEView* aFloatingTEView;
if (fTEView == NULL)
{
aFloatingTEView = AquireFloatingTEView();
if (aFloatingTEView == NULL)
{
#if qDebug
ProgramBreak("###the aquired TEView is nil.");
#endif
//RCR exit(InstallFloatingTEView);
}
aFloatingTEView->InstallEditText(this, selectChars);
fTEView = aFloatingTEView;
}
// since the floating TE view handles dim/hilite drawing - these adorners are removed
if (fDimmed)
this->DeleteAdorner(gDimAdorner, kDontRedraw);
if (fHilite)
this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::MakeVisible(void)
{
VRect myExtent;
VPoint minToSee;
this->GetExtent(myExtent);
InsetVRect(myExtent, - 10, - 10);
minToSee.h = Min(fSize.h + 10, kMaxCoord);
minToSee.v = Min(fSize.v + 10, kMaxCoord);
this->RevealRect(myExtent, minToSee, kVisible);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::RemoveFloatingTEView(void)
{
if (fTEView != NULL)
{
fTEView->InstallEditText(NULL, False);
/*!!!*/ ReleaseFloatingTEView(fTEView);
fTEView = NULL;
}
// since the floating TE view handles dim/hilite drawing - these adorners were removed
if (fDimmed)
AddAdorner(gDimAdorner, kDontRedraw);
if (fHilite)
AddAdorner(gHiliteAdorner, kDontRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::RestartEdit(const Str255& restartText)
{
Rect area;
if (fTEView->Focus()) // First, attempt to focus the TEView
{
ClipRect(gZeroRect); /* Prevent TE from mucking up the hilite with
a stinking insertion point */
//!!!RCR InstallSelection(TRUE, False);
fTEView->SetActive(FALSE); // Deactivate the selection
SetText(restartText, kDontRedraw); // Set the text to previous value
SetSelection(0, MAXINT, kDontRedraw); // Select all characters
//!!!RCR InstallSelection(False, TRUE); */ /* Activate the selection
fTEView->SetActive(TRUE);
this->InvalidateFocus(); // Make sure we re-focus
fTEView->ForceRedraw();
}
else
SetText(restartText, kDontRedraw); // Just set the text if we can't focus
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::SetJustification(short theJust,
Boolean redraw)
{
if (fTEView != NULL)
fTEView->SetJustification(theJust, redraw);
inherited::SetJustification(theJust, redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::SetSelection(short selStart,
short selEnd,
Boolean redraw)
{
if (fTEView != NULL)
{
if (redraw && fTEView->IsDrawable())
TESetSelect(selStart, selEnd, fTEView->fHTE);
else
SetSelect(selStart, selEnd, fTEView->fHTE);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::SetText(const Str255& theText,
Boolean redraw) // override
{
Str255 currentText;
VRect area;
Rect qdArea;
if (fTEView != NULL)
{
this->GetText(currentText);
if (currentText != theText)
{
fTEView->SetText(theText);
fTEView->RecalcText();
fTEView->SynchView(kDontRedraw);
if (redraw && this->IsDrawable())
{
this->ControlArea(area);
this->ViewToQDRect(area, qdArea);
EraseRect(qdArea);
this->DrawContents();
}
}
}
else
inherited::SetText(theText, redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::InstallSelection(Boolean wasActive,
Boolean beActive) // override
{
if (fTEView != NULL)
fTEView->InstallSelection(wasActive, beActive);
else if (beActive)
/*!!!RCR*/ this->StartEdit(TRUE);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TEditText::ResignTarget(void) // override
{
inherited::ResignTarget();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::StartEdit(Boolean selectChars)
{
this->InstallFloatingTEView(selectChars);
this->SetTarget(fTEView);
this->MakeVisible();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TEditText::StopEdit(void)
{
Str255 aString;
if (fTEView != NULL)
{
this->GetText(aString); /* Must get the text before removing
the floating TEView */
// fTEView->InstallSelection(TRUE, FALSE);
this->RemoveFloatingTEView();
this->SetText(aString, kDontRedraw);
}
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal long TEditText::Validate(void)
{
long validateResult;
validateResult = inherited::Validate();
if ((validateResult == kValidValue)
&& (fTEView != NULL)
&& (GetHandleSize(fTEView->fText) > fMaxChars))
validateResult = kTooManyCharacters;
return validateResult;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal Boolean TEditText::WantToBecomeTarget(void) // override
{
return ( (fTEView == NULL) && this->IsEnabled()) /* && this.IsActive*/;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal long TEditText::WillingToResignTarget(void) // override
{
return inherited::WillingToResignTarget();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TNumberText::Initialize(void) // override
{
inherited::Initialize();
fMaximum = MAXLONGINT;
fMinimum = 0;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TNumberText::INumberText(TView* itsSuperView,
const VPoint& itsLocation,
const VPoint& itsSize,
long itsValue,
long itsMinimum,
long itsMaximum)
{
this->IEditText(itsSuperView, itsLocation, itsSize, 255);
#if qDebug
if (itsMinimum > itsMaximum)
cout << "Minimum value specified is greater than maximum for TNumberText.\n";
#endif
fMinimum = itsMinimum;
fMaximum = itsMaximum;
this->SetValue(itsValue, kDontRedraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgOpen
pascal void TNumberText::IRes(TDocument* ,
TView* itsSuperView,
Ptr& itsParams) // override
{
inherited::IRes(NULL, itsSuperView, itsParams);
NumberTextTemplate& templateData = (NumberTextTemplate&) *itsParams;
#if qDebug
if (templateData.minimum > templateData.maximum)
cout << "Minimum value specified is greater than maximum for TNumberText.\n";
#endif
fMinimum = templateData.minimum;
fMaximum = templateData.maximum;
this->SetValue( templateData.value, kDontRedraw);
OffsetPtr(itsParams, sizeof(NumberTextTemplate));
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TNumberText::WRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
inherited::WRes(theResource, itsParams);
NumberTextTemplate& templateData =
(NumberTextTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(NumberTextTemplate)));
templateData.value = this->GetValue();
templateData.minimum = fMinimum;
templateData.maximum = fMaximum;
}
//--------------------------------------------------------------------------------------------------
#pragma segment MAWriteRes
pascal void TNumberText::WriteRes(ViewRsrcHandle theResource,
Ptr& itsParams) // override
{
gWResSignature = 'nmbr'; gWResType = "TNumberText";
WRes(theResource, itsParams);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal long TNumberText::GetValue(void)
{
Str255 aString;
long theValue;
this->GetText(aString);
StringToNum(aString, theValue);
return theValue;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal void TNumberText::SetValue(long newValue,
Boolean redraw)
{
Str255 aString;
newValue = Max(fMinimum, Min(fMaximum, newValue));
NumToString(newValue, aString);
this->SetText(aString, redraw);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgNonRes
pascal long TNumberText::Validate(void) // override
{
Str255 theString;
decimal decRec;
extended extValue;
short index;
short validPrefix = 0;
long result;
result = kValidValue;
//!!! This really begs for a fRequired field to test when the string is left empty
// Then we would inform the user that an empty string is not a valid option.
// Also a fDefault field is necessary. GetValue would return fDefault rather
// than 0 when the string is empty. For now (2.0) we will not validate an empty
// string and assume that if the user wants a value they will override.
this->GetText(theString);
if (theString != "")
{
index = 1;
str2dec( p2cstr(&theString), index, decRec, validPrefix); //!!! Note p2cstr
if (validPrefix && (index > theString.Length()) && (decRec.exp >= 0))
{
extValue = dec2num(decRec);
if (extValue < fMinimum)
result = kValueTooSmall;
else
if (extValue > fMaximum)
result = kValueTooLarge;
}
else
result = kNonNumericCharacters;
}
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TNumberText::Fields(TObject* obj) // override
{
obj->DoToField("TNumberText", NULL, bClass);
obj->DoToField("fMinimum", &fMinimum, bLongInt);
obj->DoToField("fMaximum", &fMaximum, bLongInt);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgInit
pascal void TFloatingTEManager::Initialize(void) // override
{
inherited::Initialize();
fCache = NULL;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgClose
pascal void TFloatingTEManager::Free(void) // override
{
if (fCache != NULL)
fCache = (TDialogTEView*)(FreeIfObject(fCache));
inherited::Free();
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgFields
pascal void TFloatingTEManager::Fields(TObject* obj) // override
{
obj->DoToField("TFloatingTEManager", NULL, bClass);
obj->DoToField("fCache", &fCache, bObject);
inherited::Fields(obj);
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TDialogTEView* TFloatingTEManager::AquireFloatingTE(void)
{
TDialogTEView* result;
if (fCache != NULL) // Got one in the cache!
{
result = fCache;
fCache = NULL; // Cache is now empty
}
else
result = this->MakeDialogTEView();
return result;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal TDialogTEView* TFloatingTEManager::MakeDialogTEView(void)
{
TDialogTEView* aDialogTEView = NULL;
if (qTemplateViews && (gApplication != NULL))
aDialogTEView = (TDialogTEView*)(gApplication->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
else
{
aDialogTEView = new TDialogTEView;
aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable,
gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, False);
}
aDialogTEView->fMinAhead = 1; /* Don't _jump_ the view ahead when
autoscrolling for scrollselectionintoview
*/
return aDialogTEView;
}
//--------------------------------------------------------------------------------------------------
#pragma segment DlgRes
pascal void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
{
if (fCache == NULL)
fCache = aDialogTEView;
else
aDialogTEView->Free();
}